<!--
 * @Author: zhangjingyu
 * @Date: 2021-04-13 14:10:00
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-05-19 10:47:52
 * @FilePath: \vprisk10.14\src\views\ftpManage\pricingManage\hisBusiRepricing\rp_engineTasks.vue
 * @Description: 重定价引擎任务
-->
<template>
  <div>
    <span class="formTitle"><i class="vertical-bar"></i>重定价引擎任务</span>
    <el-form
      :model="searchForm"
      ref="blockRef"
      label-width="100px"
      label-position="right"
      size="mini"
    >
      <el-row :gutter="30">
        <el-col :span="4">
          <el-form-item label="任务名称：" prop="taskName">
            <el-input v-model="taskName" maxlength="32" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="定价编号：" prop="pricingCode">
            <el-input
              v-model="searchForm.pricingCode"
              maxlength="32"
              disabled
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="数据日期：" prop="dataDate">
            <el-date-picker
              v-model="searchForm.dataDate"
              type="date"
              value-format="yyyy-MM-DD"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item label="表名称：" prop="positions">
            <el-select v-model="searchForm.pdName" placeholder="请选择">
              <el-option
                v-for="item in positionOptions"
                :key="item.pdPostfix"
                :label="item.pdName"
                :value="item.pdPostfix"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3"
          ><el-button @click="searchFunc">查询</el-button>
          <el-button
            @click="(searchForm.dataDate = ''), (searchForm.pdName = '')"
            >重置</el-button
          ></el-col
        >
      </el-row>
    </el-form>
    <el-row class="container">
      <upper-template :searchIcon="false" :configIcon="false">
        <!-- 操作按钮区 -->
        <template slot="buttonArea">
          <el-button @click="toResult()">查看结果</el-button>
          <el-button @click="backExecuteNotes()">执行记录</el-button>
          <el-button @click="backSubTasks()">子任务</el-button>
          <el-button @click="goBack()">返回</el-button>
        </template>
      </upper-template>
    </el-row>
    <el-table
      ref="table"
      :data="tableData"
      style="width: 100%"
      @row-click="rowclick"
    >
     <el-table-column
        width="55"
        type="selection"
        
      ></el-table-column>
      <el-table-column
        prop="tableName"
        label="表名称"
        :show-overflow-tooltip="true"
      ></el-table-column>
    
      <el-table-column
        prop="dataDate"
        label="数据日期"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="startAccount"
        label="开始编号"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="endAccount"
        label="结束编号"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
          prop="nodeCode"
          label="节点编号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
        prop="blockSize"
        label="块大小"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="successNum"
        label="成功记录数"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="failNum"
        label="失败记录数"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="startTm"
        label="开始时间"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="endTm"
        label="结束时间"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="status"
        label="运行状态"
          :formatter="r=>$getLabel(r.status,statusOption)"
        :show-overflow-tooltip="true"
      ></el-table-column>
    </el-table>
    <!-- 分页插件 -->
    <pagination
      @size-change="sizeChange"
      @current-change="currentChange"
      :current-page="searchForm.page"
      :page-size="searchForm.size"
      @refresh="searchFunc"
      :total="total"
    ></pagination>
  </div>
</template>

<script>
import { pricingTask } from "@/api/index";
import moment from "moment"
export default {
  props: {
    //选中的值
    baseData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      positionOptions: [],
      total: 0,
      taskName: this.baseData.taskName,
      searchForm: {
        page: 1,
        size: 15,
        taskCode: this.baseData.taskCode,
        pricingCode: this.baseData.pricingCode,
        dataDate: "",
        tableName: ""
      },
      statusOption:[],
      tableData: []
    };
  },
  created() {
    this.getstatus("ftp_pricing_task_status");
    this.toBlock();
    this.searchFunc();
  },
  methods: {
    toBlock() {
      let data = { pricingCode: this.baseData.pricingCode };
      pricingTask.pricingTasktoBlock(data).then(res => {
        if (res.code == 200) {
          this.positionOptions = res.data.positions;
          console.log(res, "biao");
        }
      });
    },
    toResult() {
      let selection = this.$refs.table.selection;
      if (selection.length != 1) return this.$message.warning("请选择一条数据");
      this.$emit("toResult",selection[0])
    },
    goBack() {
      this.$emit("backIndex");
    },
    backExecuteNotes() {
      this.$emit("backExecuteNotes");
    },
    backSubTasks() {
      this.$emit("backSubTasks");
    },
    //点击行选中
    rowclick(row) {
      if (this.$refs.table) {
        this.$refs.table.clearSelection();
      }
      this.$refs.table.toggleRowSelection(row, true);
    },
    searchFunc() {
      let data = this.searchForm;
      pricingTask.pricingRecordBlockFindAll(data).then(res => {
        if (res.code == 200) {
          this.tableData = res.datas.rows.map(v=>{
            let obj = v;
            obj.dataDate =obj.dataDate? moment(obj.dataDate).format('yyyy-MM-DD'):"-"
            return obj;
          });
          this.total = res.total;
          console.log("引擎任务", res);
        }
      });
    },
    getstatus(data) {
      this.$getDict(data).then(res => {
        if (res.code == 200) {
          this.statusOption = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    sizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
    },
    currentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
    }
  }
};
</script>

<style lang="scss" scoped>
</style>